package com.visionet.school.app.web.repository.dynamic;

import com.visionet.school.app.web.entity.dynamic.DynamicComment;
import com.visionet.school.app.web.entity.dynamic.vo.DynamicCommentVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;

/**
 * Created by hxpeng on 2017/5/27.
 */
@Repository
public interface DynamicCommentRepository extends PagingAndSortingRepository<DynamicComment,String>,JpaSpecificationExecutor<DynamicComment> {

    /**
     * 动态的评论数量
     * @param dynamicId
     * @return
     */
    @Query("select count(id) from DynamicComment as dc where dc.isDeleted = 0 and dc.dynamicId = ?1 ")
    int dynamicCommentCount(String dynamicId);

    /**
     * 评论的回复数量
     * @param parentCommentId
     * @return
     */
    @Query("select count(id) from DynamicComment as dc where dc.isDeleted = 0 and dc.parentCommentId = ?1 ")
    int commentReplyCount(String parentCommentId);

    /**
     * 加载评论
     * @param dynamicCommentVo
     * @return
     */
    Page<DynamicCommentVo> loadCommentPage(DynamicCommentVo dynamicCommentVo);
}
